package com.qf.dao;

import com.qf.pojo.Page;
import com.qf.pojo.Profile;
import com.qf.utils.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class RecordDaoImpl implements RecordDao {

    private QueryRunner runner = new QueryRunner(DBUtil.getDateSource());

    @Override
    public int selectAllByPageCount() {
        String sql = "select count(*) from profile;";
//              try {
////                  long count = runner.query(sql, new ScalarHandler<Long>());
////                  return (int)count;
//               } catch (SQLException e) {
//                    e.printStackTrace();
//                }
                return 0;

            }

    @Override
    public List<Profile> selectAllByPage(Page page) {

        String sql = "select * from profile limit ?, ?;";
        try {
            List<Profile> list = runner.query(sql, new BeanListHandler<Profile>(Profile.class), page.getStartRows(),
                    page.getPageSize());
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
